local yaoyi = fk.CreateSkill {

  name = "joy__yaoyi",

  tags = { Skill.Compulsory, },

}



yaoyi:addEffect(fk.GameStart, {
  name = "joy__yaoyi",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.GameStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(yaoyi.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(player.room:getAlivePlayers()) do
      local yes = true
      for _, skill in ipairs(p.player_skills) do
        if skill.switchSkillName then
          yes = false
          break
        end
      end
      if yes then
        room:handleAddLoseSkills(p, "joy__shoutan", nil, true, false)
      end
    end
  end,
})
yaoyi:addEffect(fk.Deathed, {
  refresh_events = {fk.Deathed},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self, true, true)
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room:getAllPlayers()) do
      room:handleAddLoseSkills(p, "-joy__shoutan", nil, true, true)
    end
  end,
})

yaoyi:addEffect(fk.AfterCardUseDeclared, {
  name = "#joy__shoutan_refresh",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.AfterCardUseDeclared},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(yaoyi.name) and player:getMark("joy__shoutan-phase") > 0 
  end,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player,"joy__shoutan-phase",0)
  end
})

yaoyi:addEffect("prohibit", {
  name = "#joy__yaoyi_prohibit",
  frequency = Skill.Compulsory,
  is_prohibited = function(self, from, to, card)
    if table.find(Fk:currentRoom().alive_players, function(p) return p:hasSkill("joy__yaoyi") end) then
      if from ~= to then
        local fromskill = {}
        for _, skill in ipairs(from.player_skills) do
          if skill.switchSkillName then
            table.insertIfNeed(fromskill, skill.switchSkillName)
          end
        end
        local toskill = {}
        for _, skill in ipairs(to.player_skills) do
          if skill.switchSkillName then
            table.insertIfNeed(toskill, skill.switchSkillName)
          end
        end
        if #fromskill == 0 or #toskill == 0 then return false end
        if #fromskill > 1 then  
        end
        return from:getSwitchSkillState(fromskill[1], false) == to:getSwitchSkillState(toskill[1], false)
      end
    end
  end,
})

return yaoyi